package com.example.xjt.restful;

import lombok.Getter;

@Getter
public class APIException extends RuntimeException {
    private int code;
    private String msg;

    //强制程序员使用自己添加的枚举,所以定为private
    private APIException(int code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }


    //默认throw出的异常，不想定义枚举，可以统一定为9500响应失败
    public APIException() {
        this(ResultCodeEnum.FAILED.getCode(), ResultCodeEnum.FAILED.getMsg());
    }

    //若想自定义throw出的异常枚举，则先建立枚举，再在业务层throw出这个异常
    public APIException(ResultCodeEnum resultCodeEnum) {
        this(resultCodeEnum.getCode(), resultCodeEnum.getMsg());
    }
}